package com.chinairi.mall.controller;


import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.*;
import com.chinairi.mall.model.ProjectPlanPurchase;
import com.chinairi.mall.model.ProjectPlanReqDetail;
import com.chinairi.mall.model.UserCompanyInfo;
import com.chinairi.mall.service.IProjectPlanPurchaseService;
import com.chinairi.mall.service.modelobject.CompShopMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gsl
 * @since 2020-09-19
 */
@RestController
@RequestMapping("/project-plan-purchase")
public class ProjectPlanPurchaseController extends BaseController {


    @Autowired
    private IProjectPlanPurchaseService iProjectPlanPurchaseService;

    /**
     * 生成采购计划
     *
     * @param projectPlanPurchaseVO
     * @throws IOException
     */
    @PostMapping("/add")
    public void add(@RequestBody ProjectPlanPurchaseVO projectPlanPurchaseVO) throws IOException {
        iProjectPlanPurchaseService.add(projectPlanPurchaseVO);
        ResponseUtil.showMessage("success", "生成采购计划成功", "");
    }

    /**
     * 查询某个需求计划下的采购计划
     *
     * @param
     * @throws IOException
     */
    @GetMapping("/getList")
    public void getList(String planReqId) throws IOException {
        List<ProjectPlanPurchase> projectPlanPurchaseList = iProjectPlanPurchaseService.getList(planReqId);
        ResponseUtil.showMessage("success", "获取采购计划成功", projectPlanPurchaseList);
    }

    /**
     * 查询某个需求计划下的采购计划
     *
     * @param
     * @throws IOException
     */
    @GetMapping("/getAllList")
    public void getAllList() throws IOException {
        List<ProjectPlanPurchaseVO> projectPlanPurchaseVOList = iProjectPlanPurchaseService.getAllList();
        ResponseUtil.showMessage("success", "获取采购计划成功", projectPlanPurchaseVOList);
    }


    /**
     * 根据采购计划id获取计划下的物料列表
     *
     * @param planPurchaseId
     * @throws IOException
     */
    @GetMapping("/getReqDetail")
    public void getReqDetail(String planPurchaseId) throws IOException {
        List<ProjectPlanReqDetail> projectPlanReqDetailList = iProjectPlanPurchaseService.getReqDetail(planPurchaseId);
        ResponseUtil.showMessage("success", "获取采购计划详情成功", projectPlanReqDetailList);
    }

    /**
     * 获取采购计划中供应商排行
     *
     * @param planPurchaseId 采购计划id
     * @throws IOException
     */
    @GetMapping("/getShopRankList")
    public void getShopRankList(String planPurchaseId) throws IOException {
        Map<String, List<CompShopMO>> map = iProjectPlanPurchaseService.getShopRankList(planPurchaseId);
        ResponseUtil.showMessage("success", "获取供应商排行榜成功", map);
    }


    /**
     * 根据传入的商品id查找商品详细信息
     *
     * @throws IOException
     */
    @GetMapping("/getCollectByShop")
    public void getCollectByShop(@RequestParam("goodsDbidList") List<String> goodsDbidList) throws IOException {
        List<GoodsInfoVO> goodsInfoVOList = iProjectPlanPurchaseService.getCollectByShop(goodsDbidList);
        ResponseUtil.showMessage("success", "获取批量采购商品成功", goodsInfoVOList);
    }

    /**
     * 采购计划添加服务
     *
     * @param stringObjectMap
     * @throws IOException
     */
    @PostMapping("/addService")
    public void addService(@RequestBody HashMap<String, Object> stringObjectMap) throws IOException {
        iProjectPlanPurchaseService.addService(stringObjectMap);
        ResponseUtil.showMessage("success", "采购计划服务添加成功", "");
    }

    /**
     * 根据采购计划ID获取采购计划下的服务
     *
     * @throws IOException
     */
    @GetMapping("/getService")
    public void getService(String planPurchaseId) throws IOException {
        ProjectPlanPurchaseServiceVO projectPlanPurchaseServiceVO = iProjectPlanPurchaseService.getService(planPurchaseId);
        ResponseUtil.showMessage("success", "获取采购计划服务成功", projectPlanPurchaseServiceVO);
    }

    /**
     * 更新采购计划中的服务
     *
     * @param purchaseServiceVO
     * @throws IOException
     */
    @PostMapping("/addOrUpdateService")
    public void addOrUpdateService(@RequestBody ProjectPlanPurchaseServiceVO purchaseServiceVO) throws IOException {
        iProjectPlanPurchaseService.addOrUpdateService(purchaseServiceVO);
        ResponseUtil.showMessage("success", "更新采购计划服务成功", "");
    }

    /**
     * 获取对应服务的服务商下拉列表
     *
     * @param serviceType
     * @throws IOException
     */
    @GetMapping("/getServerCompByType")
    public void getServerCompByType(String serviceType) throws IOException {
        List<UserCompanyInfo> userCompanyInfoVOList = iProjectPlanPurchaseService.getServerCompByType(serviceType);
        ResponseUtil.showMessage("success", "获取服务商列表成功", userCompanyInfoVOList);
    }


}
